package Greedy;

import java.util.Arrays;

public class 无重叠区间 {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0]));
        int res = 0;
        int end = intervals[0][1];
        for (int i = 1; i < intervals.length; i++) {
            if (intervals[i][0] < end) {
                res++;
                if (intervals[i][1] < end) end = intervals[i][1];
            } else end = intervals[i][1];
        }
        return res;
    }
}
